<?php
namespace app\api\controller\v1;
use think\admin\Controller;
use think\Response;
use app\data\model\DataWarningLog;
/**
 * 通知接口
 * @class Notice
 * @package app\api\controller\v1
 *
 */
class Notice extends Controller
{
    //设备异常通知
    public function warning()
    {
        $res = DataWarningLog::mk()->alias('l')->field('l.id,l.msg as description,l.create_at,l.is_read,d.nickname')
            ->join('data_device d','d.iotId = l.iot_id ')
            ->where(['d.member_id'=>$this->request->uid])->order('l.is_read asc,l.create_at desc')->paginate(10);
        $this->success('success',$res);
    }
    public function read(){
        $id = input('post.id');
        $map[]=['member_id','=',$this->request->uid];
        if($id>0){
            $map[]=['l.id','=',$id];
        }
        DataWarningLog::mk()->alias('l')
            ->where($map)
            ->join('data_device d','d.iotId = l.iot_id ')
            ->update(['is_read'=>1]);
        $this->success('success',$id);
    }
}
